Import a stripped down version of gcc-4.1.1
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / value_type_adapter / it_value_type_traits.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
39
40 /**
41  * @file it_value_type_traits.hpp
42  * Contains an adapter of mapping levels.
43  */
44
45 template<class Base, bool Lowest>
46 struct base_it_key_type
47 {
48   typedef typename Base::it_key_type type;
49 };
50
51 template<class Base>
52 struct base_it_key_type<
53   Base,
54   true>
55 {
56   typedef typename Base::const_key_reference type;
57 };
58
59 template<typename Base_Key_,
60          typename Key_,
61          typename Data_,
62          typename Value_,
63          class Allocator_ >
64 struct it_value_type_traits_
65 {
66   typedef ref_pair< Base_Key_, Key_> key_ref_pair;
67
68   typedef
69   typename Allocator_::template rebind<
70     key_ref_pair>::other::const_reference
71   key_ref_pair_val;
72
73   typedef key_ref_pair_val key_type;
74
75   typedef ref_pair< key_ref_pair_val, Data_> value_type;
76
77   typedef
78   typename Allocator_::template rebind<
79     value_type>::other::reference
80   reference;
81
82   typedef
83   typename Allocator_::template rebind<
84     value_type>::other::const_reference
85   const_reference;
86
87   typedef
88   typename Allocator_::template rebind<
89     value_type>::other::pointer
90   pointer;
91
92   typedef
93   typename Allocator_::template rebind<
94     value_type>::other::const_pointer
95   const_pointer;
96
97   struct value_type_holder
98   {
99     typename std::tr1::aligned_storage<sizeof(key_ref_pair),
100       std::tr1::alignment_of<key_ref_pair>::value>::type  m_a_key_buf;
101
102     typename std::tr1::aligned_storage<sizeof(value_type),
103       std::tr1::alignment_of<value_type>::value>::type  m_a_value_buf;
104   };
105
106   typedef
107   typename Allocator_::template rebind<
108     value_type_holder>::other::reference
109   value_type_hoder_valerence;
110
111   inline static pointer
112   recast(value_type_hoder_valerence r_holder)
113   {
114     return reinterpret_cast<pointer>(&r_holder.m_a_value_buf);
115   }
116
117   inline static void
118   make_valid(value_type_hoder_valerence r_holder, Base_Key_ r_bk, Value_ r_val)
119   {
120     typedef
121       typename Allocator_::template rebind<
122       void* >::other::value_type
123       void_pointer;
124
125     void_pointer p_target = &r_holder.m_a_key_buf;
126
127     new (p_target) key_ref_pair(r_bk, r_val.first);
128
129     typedef
130       typename Allocator_::template rebind<
131       key_ref_pair>::other::pointer
132       key_ref_pair_pointer;
133
134     key_ref_pair_pointer p_key =
135       reinterpret_cast<key_ref_pair_pointer>(&r_holder.m_a_key_buf);
136
137     p_target = &r_holder.m_a_value_buf;
138
139     new (p_target) value_type(*p_key, r_val.second);
140   }
141 };
142
143 template<typename Base_Key_,
144          typename Key_,
145          typename Value_,
146          class Allocator_>
147 struct it_value_type_traits_<
148   Base_Key_,
149   Key_,
150   null_data_type,
151   Value_,
152   Allocator_>
153 {
154   typedef ref_pair< Base_Key_, Key_> key_ref_pair;
155
156   typedef
157   typename Allocator_::template rebind<
158     key_ref_pair>::other::const_reference
159   key_ref_pair_val;
160
161   typedef key_ref_pair_val key_type;
162
163   typedef key_ref_pair value_type;
164
165   typedef
166   typename Allocator_::template rebind<
167     value_type>::other::const_reference
168   reference;
169
170   typedef
171   typename Allocator_::template rebind<
172     value_type>::other::const_reference
173   const_reference;
174
175   typedef
176   typename Allocator_::template rebind<
177     value_type>::other::const_pointer
178   pointer;
179
180   typedef
181   typename Allocator_::template rebind<
182     value_type>::other::const_pointer
183   const_pointer;
184
185   struct value_type_holder
186   {
187     typename std::tr1::aligned_storage<sizeof(key_ref_pair),
188       std::tr1::alignment_of<key_ref_pair>::value>::type  m_a_key_buf;
189
190     typename std::tr1::aligned_storage<sizeof(value_type),
191       std::tr1::alignment_of<value_type>::value>::type  m_a_value_buf;
192   };
193
194   typedef
195   typename Allocator_::template rebind<
196     value_type_holder>::other::reference
197   value_type_hoder_valerence;
198
199   inline static pointer
200   recast(value_type_hoder_valerence r_holder)
201   {
202     return reinterpret_cast<pointer>(&r_holder.m_a_value_buf);
203   }
204
205   inline static void
206   make_valid(value_type_hoder_valerence r_holder, Base_Key_ r_bk, Value_ r_val)
207   {
208     typedef
209       typename Allocator_::template rebind<
210       void* >::other::value_type
211       void_pointer;
212
213     void_pointer p_target = &r_holder.m_a_value_buf;
214
215     new (p_target) key_ref_pair(r_bk, r_val.first);
216   }
217 };
218